package com.yyplatform.admin.platform.config.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.yyplatform.admin.platform.config.model.entity.SysConfigEntity;


/**
 * Created on 2024-09-12
 */
public interface SysConfigRepository extends
        JpaRepository<SysConfigEntity, Long>, JpaSpecificationExecutor<SysConfigEntity> {
    @Query(
            value =
                    "SELECT * FROM sys_config WHERE 1=1 "
                            + " AND if(:code != '' , `code` = :code, 1=1 )  ",
            countQuery =
                    "SELECT count(id) FROM sys_config WHERE 1=1 "
                            + " AND if(:code != '' , `code` = :code, 1=1 )  ",
            nativeQuery = true)
    Page<SysConfigEntity> findPage(@Param("code") String code, PageRequest pageRequestOrderByIdDesc);

    SysConfigEntity findByCode(String configKey);

}
